package com.qst.action.question;

import com.qst.BaseServlet;
import com.qst.RequestUtil;
import com.qst.WebUtil;
import com.qst.entity.AssessmentType;
import com.qst.entity.Question;
import com.qst.service.AssessmentService;
import com.qst.service.QuestionService;
import com.qst.service.impl.ServiceFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

//@WebServlet("/question/list.action")
public class ListServlet extends BaseServlet {
//    private AssessmentService assessmentService = ServiceFactory
//            .getService(AssessmentService.class);
//    private QuestionService questionService = ServiceFactory
//            .getService(QuestionService.class);
//
//    @Override
//    protected void doAction(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        String submitButton = RequestUtil.getString(req, "create");
//
//        if (submitButton.length() > 0)
//        {
//            doCreate(req, resp);
//        } else {
//            doList(req, resp);
//        }
//    }
//
//    private void doCreate(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        QuestionQueryParam param = QuestionQueryParam.create(req);
//        req.setAttribute("assessment",
//                assessmentService.findAssessmentById(param.getAssessmentId()));
//        Question question = new Question();
//        question.setType(param.getType());
//        question.setDifficulty(4);
//        req.setAttribute("question", question);
//        WebUtil.forward(req, resp, "/question/create.jsp");
//    }
//
//    protected void doList(HttpServletRequest req, HttpServletResponse resp)
//            throws ServletException, IOException {
//        List<AssessmentType> assessmentList = assessmentService.findAllAssessment();
//        req.setAttribute("assessmentList", assessmentList);
//
//        QuestionQueryParam param = QuestionQueryParam.create(req);
//        req.setAttribute("query", param);
//        List<Question> questionList = questionService.find(param);
//        req.setAttribute("questionList", questionList);
//        WebUtil.forward(req, resp, "/question/list.jsp");
//    }
}
